package com.demo.controller;

import java.util.HashMap;
import java.util.Map;

public class BaseRestController {
	
	/**
	 * 统一返回json的格式
	 * @return
	 */
	public Map<String, Object> initialMessage() {
		Map<String , Object> returnMap = new HashMap<String, Object>();
		returnMap.put("code", 100);
		returnMap.put("success", Boolean.TRUE);
		returnMap.put("msg", "");
		returnMap.put("data", null);
		return returnMap;
	}
	
	/**
	 * return error message.
	 * @param resultMap
	 * @param errorCode
	 * @param msg
	 */
	public void provcessError(Map<String, Object> resultMap,int errorCode,String msg) {
		
		if (resultMap!=null) {
			resultMap.put("code", errorCode);
			resultMap.put("success", Boolean.FALSE);
			resultMap.put("msg", msg);
		}
	}
}
